#include<iostream>
using namespace std;

void Test1()
{
	/*int* p1 = (int*)malloc(sizeof(int));
	free(p1);

	int* p2 = (int*)calloc(4, sizeof(int));
	int* p3 = (int*)realloc(p2, sizeof(int) * 10);
	free(p3);*/

	int* p4 = new int;
	int* p5 = new int(5);
	int* p6 = new int[6] {1, 2, 3, 4, 5, 6};
	delete p4;
	delete p5;
	delete[] p6;
}

//void* malloc(size_t size);
//void* calloc(size_t num, size_t size);
//void* realloc(void* ptr, size_t size);

class A
{
public:
	A(int a = 10)
		:_a(a)
	{
		cout << "A(int a = 10)" << this << endl;
	}
	~A()
	{
		cout << "~A()" << this << endl;
	}
private:
	int _a;
};

void Test2()
{
	A* p1 = (A*)malloc(sizeof(A));
	A* p2 = new A(20);
	free(p1);
	delete p2;

	A* p3 = (A*)malloc(sizeof(A) * 10);
	A* p4 = new A[10]{ 20,30,40 };
	free(p3);
	delete[] p4;
}

void Test3()
{
	A* p1 = (A*)malloc(sizeof(A));
	new(p1)A;
	p1->~A();
	free(p1);

	A* p2 = (A*)operator new (sizeof(A));
	new(p2)A(20);
	p2->~A();
	operator delete(p2);
}

int main()
{
	//Test1();
	//Test2();
	Test3();
	return 0;
}


//int globalVar					= 1;
//static int staticGlobalVar		= 1;
//
//void Test()
//{
//	static int staticVar = 1;
//	int localVar		= 1;
//	int num1[10]		= { 1, 2, 3, 4 };
//	char char2[]		= "abcd";
//	const char* pChar3	= "abcd";
//	int* ptr1			= (int*)malloc(sizeof(int) * 4);
//	int* ptr2			= (int*)calloc(4, sizeof(int));
//	int* ptr3			= (int*)realloc(ptr2, sizeof(int) * 4);
//	
//	free(ptr1);
//	free(ptr3);
//}